<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="contentscript.js"></script>
    <script>
        /**
         * Returns a handler which will open a new window when activated.
         */
        function rotateClockWise() {
            return function (info, tab1) {
                chrome.tabs.getSelected(null, function(tab) {
                    chrome.tabs.sendRequest(tab.id, {angle: 90, rotation: 'rotate'}, function(response) {

                    });
                });
            };
        }

        function rotateCounterClockWise() {
            return function (info, tab1) {
                chrome.tabs.getSelected(null, function(tab) {
                    chrome.tabs.sendRequest(tab.id, {angle: -90, rotation: 'rotate'}, function(response) {

                    });
                });
            };
        }

        function upright() {
            return function (info, tab1) {
                chrome.tabs.getSelected(null, function(tab) {
                    chrome.tabs.sendRequest(tab.id, {angle: 0, rotation: 'flip'}, function(response) {

                    });
                });
            };
        }

        function upsideDown() {
            return function (info, tab1) {
                chrome.tabs.getSelected(null, function(tab) {
                    chrome.tabs.sendRequest(tab.id, {angle: 180, rotation: 'flip'}, function(response) {

                    });
                });
            };
        }


        /**
         * Create a context menu which will only show up for images.
         */
        chrome.contextMenus.create({
                    "title" : "Rotate CW",
                    "type" : "normal",
                    "contexts" : ["all"],
                    "onclick" : rotateClockWise()
                });

        chrome.contextMenus.create({
                    "title" : "Rotate CCW",
                    "type" : "normal",
                    "contexts" : ["all"],
                    "onclick" : rotateCounterClockWise()
                });

        chrome.contextMenus.create({
                    "title" : "Upside Down",
                    "type" : "normal",
                    "contexts" : ["all"],
                    "onclick" : upsideDown()
                });

        chrome.contextMenus.create({
                    "title" : "Upright",
                    "type" : "normal",
                    "contexts" : ["all"],
                    "onclick" : upright()
                });
    </script>
</head>
<body>
</body>
</html>